package jsave.action;

import java.io.File;

import jsave.exception.JSaveArretSauvegarde;

import org.apache.log4j.Logger;

public class ActionCopier extends Action {
	
	private static final Logger log = Logger.getLogger(ActionCopier.class);
	
	public ActionCopier(int typeAction) {
		
		super();
		
		if (typeAction == Action.ACTION_A || typeAction == Action.ACTION_B) {
			this.typeAction = typeAction;
		} else {
			log.error("ERREUR - Le type d'action '"+typeAction+"' ne correspond pas a l'action 'ActionCopier' ");
		}
	}
	
	public void executer(File s, File d) throws JSaveArretSauvegarde {
		
		if (typeAction == Action.ACTION_A) { // ACTION_A
			if (s.isDirectory())
				creerDossier(d);
			else
				ajouterFichier(s,d);
		} else { // ACTION_B
			if (s.isDirectory())
				creerDossier(s);
			else
				ajouterFichier(d, s);
		}
	}

	public String getNom() {
		return "COPIER";
	}
}
